<?php
/**
 * Created by PhpStorm.
 * User: Jerry
 * Date: 2016/12/17
 * Time: 11:40
 */

namespace SDXApi\Model;


use Think\Model;

/**
 * Class SeminarPageModel
 * @package SDXApi\Model
 */
class SeminarPageModel extends Model
{
	/**
	 * @var string
	 */
	protected $tableName = 'seminar_template_pages';


    /**
     * Created by Jerry
     * @param $id
     * @param int $pageNumber
     * @param int $pageSize
     * @return mixed
     */
    public function find_seminar_template_pages_by_template_id($id, $pageNumber = 0, $pageSize = 0)
    {
        if ($pageNumber) {
            $pageArr = show_page($pageSize, $pageNumber, 5);
            $limit = $pageArr['firstpage'] . ',' . 5;
        } else {
            $limit = '';
        }

        $where = array(
            'template_id'	=>	$id,
        );

        return $this->where($where)->order('sort desc')->limit($limit)->select();
    }

    /**
     * @author Min
     * @param $id
     * @return mixed
     */
    public function find_seminar_template_pages_count_by_template_id($id)
    {
        $where = array(
            'template_id'	=>	$id,
        );

        return $this->where($where)->count();
    }

	/**
	 * 专辑
	 * Created by Jerry
	 * @param $template_id
	 * @return mixed
	 */
	public function find_seminar_template_album_by_template_id($template_id)
	{
		$time = time();
		$where = array(
			'sa.page_id'		=>	$template_id,
			'a.start_time'		=>	array('LT', $time,),
			'a.end_time'		=>	array('GT', $time,),
		);

		$field = 'a.id, a.name, a.small, a.description';

		$data = $this
			->table('sdx_seminar_template_album')
			->alias('sa')
			->field($field)
			->join('LEFT JOIN __ALBUM__ AS a ON sa.album_id = a.id')
			->where($where)
			->group('sa.album_id')
			->select();

		return $data;
	}
}